package com.yue92.datalife.service.impl;

import com.yue92.datalife.model.Moment;
import com.yue92.datalife.repository.MomentRepository;
import com.yue92.datalife.service.AbstractDbService;
import com.yue92.datalife.service.IMomentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MomentServiceImpl extends AbstractDbService<Moment, Long> implements IMomentService {

    @Autowired
    private MomentRepository momentRepository;

    @Override
    public List<Moment> findAll() {
        Sort sort = Sort.by(Sort.Direction.ASC, "sort").and(Sort.by(Sort.Direction.ASC, "id"));
        return momentRepository.findByDisplay(true, sort);
    }

    @Override
    public JpaRepository<Moment, Long> getRepository() {
        return momentRepository;
    }

    @Override
    protected Class<Moment> getModelClass() {
        return Moment.class;
    }
}
